function SumList() {

}

SumList.prototype.run = function () {
    var self = this;
    self.listenSumEvent();
};


SumList.prototype.listenSumEvent = function () {
    //注意：导航 依赖 element 模块，否则无法进行功能性操作
    layui.use(['table', 'form', 'element', 'layer', 'laydate'], function () {
        var table = layui.table,
            form = layui.form,
            layer = layui.layer,
            laydate = layui.laydate,
            element = layui.element;

        // ******************************************

        //选项卡切换刷新
        var layid = location.hash.replace(/^#warn-tab=/, '');
        element.tabChange('warn-tab', layid);

        // 监听tab切换，改变地址hash值
        element.on('tab(warn-tab)', function (data) {
            location.hash = 'warn-tab=' + this.getAttribute('lay-id');
        });

        // ******************************************

        // 选项卡 - 已发送
        var check_value1 = [];
        var check_dev1 = [];
        var check_manage1 = [];
        var check_day1 = [];
        var check_alarm1 = [];
        var times1 = [];
        table.render({
            elem: '#table-sum1',
            height: 'full', // 表格高度始终填满
            // even: true, //　列表隔行颜色
            size: 'lg',
            method: 'get', // 请求方法
            url: '/warn_list/newsum_list/', // 数据接口
            where: {
                is_make: 2,
                check_value: check_value1,
                check_dev: check_dev1,
                check_manage: check_manage1,
                check_day: check_day1,
                check_alarm: check_alarm1,
                times: times1,
                is_sum: 1,
            },
            page: true, // 开启分页　可传入laypage参数
            toolbar: '#warn-tool',
            limit: 6,
            limits: [6, 20, 50, 100, 200],
            text: '暂无数据...',
            cols: [
                [ // 表头　需要显示的数据列
                    // {
                    //     type: 'checkbox',
                    //     fixed: 'left'
                    // },
                    {
                        field: 'event_id',
                        title: '预警编号',
                        sort: true,
                    },
                    {
                        field: 'type_name',
                        title: '任务类型',
                    },
                    {
                        field: 'warn_type',
                        title: '预警类型',
                    },
                    {
                        field: 'map_name',
                        title: '所属监控点',
                    },
                    {
                        field: 'result',
                        title: '当前状态'
                    },
                    {
                        field: 'user',
                        title: '平台处理员'
                    },
                    {
                        field: 'add_time',
                        title: '发生时间',
                        sort: true,
                    },
                    {
                        field: 'warn_url',
                        title: '事件图片',
                        templet: '#sum-image',
                        align: 'center',
                        width: 210
                    },
                    {
                        field: 'images',
                        title: '证据图片',
                        templet: '#warn-image',
                        align: 'center',
                        hide: true
                    },
                    {
                        field: 'video_url',
                        title: '证据视频',
                        templet: '#warn-video',
                        align: 'center',
                    },
                ]
            ]
        });

        table.on('toolbar(warnlist1)', function (obj) {
            switch (obj.event) {
                // 任务类型筛选
                case 'manage-select':
                    layer.open({
                        resize: false,
                        type: 1,
                        title: '请勾选任务类型',
                        content: $('#layer-manage-select'),
                        offset: ['200px', '300px'],
                        area: ['300px', '200px'],
                        btn: ['确认', '取消'],
                        yes: function (index) {
                            obj = document.getElementsByName('manage');
                            check_val = [];
                            for (k in obj) {
                                if (obj[k].checked) {
                                    check_val.push(obj[k].value);
                                }
                            }
                            var new_val = check_val.join(',');
                            check_manage1 = new_val;

                            if (check_manage1.length != 0) {
                                table.reload('table-sum1', {
                                    where: {
                                        check_manage: check_manage1,
                                        is_sum: 1,
                                    },
                                    url: '/warn_list/newsum_list/', // 数据接口
                                });
                            } else if (check_manage1.length == 0) {
                                parent.location.reload();
                            }
                            layer.close(index);
                        }
                    });
                    break;

                // 预警类型筛选
                case 'warn-select':
                    layer.open({
                        resize: false,
                        type: 1,
                        title: '请勾选预警类型',
                        content: $('#layer-warn-select'),
                        offset: ['200px', '400px'],
                        area: ['300px', '200px'],
                        btn: ['确认', '取消'],
                        yes: function (index) {
                            obj = document.getElementsByName('warn');
                            check_val = [];
                            for (k in obj) {
                                if (obj[k].checked) {
                                    check_val.push(obj[k].value);
                                }
                            }
                            var new_val = check_val.join(',');
                            check_value1 = new_val;

                            if (check_value1.length != 0) {
                                table.reload('table-sum1', {
                                    where: {
                                        check_value: check_value1,
                                        is_sum: 1,
                                    },
                                    url: '/warn_list/newsum_list/', // 数据接口
                                });
                            } else if (check_value1.length == 0) {
                                parent.location.reload();
                            }
                            layer.close(index);
                        }
                    });
                    break;

                // 事件类型
                case 'alarm-select':
                    layer.open({
                        resize: false,
                        type: 1,
                        title: '请勾选条件',
                        content: $('#layer-alarm-select'),
                        offset: ['200px', '500px'],
                        area: ['300px', '200px'],
                        btn: ['确认', '取消'],
                        yes: function (index) {
                            obj = document.getElementsByName('alarm');
                            check_alarm = [];
                            for (k in obj) {
                                if (obj[k].checked) {
                                    check_alarm.push(obj[k].value);
                                }
                            }
                            var new_alarm = check_alarm.join(',');
                            check_alarm1 = new_alarm;

                            if (check_alarm1.length != 0) {
                                table.reload('table-sum1', {
                                    where: {
                                        check_alarm: check_alarm1,
                                        is_sum: 1,
                                    },
                                    url: '/warn_list/newsum_list/', // 数据接口
                                });
                            } else if (check_alarm1.length == 0) {
                                parent.location.reload();
                            }
                            layer.close(index);
                        }
                    });
                    break;

                // 昼夜筛选
                case 'day-select':
                    layer.open({
                        resize: false,
                        type: 1,
                        title: '请勾选条件',
                        content: $('#layer-day-select'),
                        offset: ['200px', '500px'],
                        area: ['300px', '200px'],
                        btn: ['确认', '取消'],
                        yes: function (index) {
                            obj = document.getElementsByName('day');
                            check_day = [];
                            for (k in obj) {
                                if (obj[k].checked) {
                                    check_day.push(obj[k].value);
                                }
                            }
                            var new_val = check_day.join(',');
                            check_day1 = new_val;

                            if (check_day1.length != 0) {
                                table.reload('table-sum1', {
                                    where: {
                                        check_day: check_day1,
                                        is_sum: 1,
                                    },
                                    url: '/warn_list/newsum_list/', // 数据接口
                                });
                            } else if (check_day1.length == 0) {
                                parent.location.reload();
                            }
                            layer.close(index);
                        }
                    });
                    break;

                // 时间筛选
                case 'time-select':
                    layer.open({
                        resize: false,
                        type: 1,
                        title: '筛选时间',
                        content: $('#layer-time-select1'),
                        offset: ['200px', '600px'],
                        area: ['600px', '480px'],
                        success: function (layero, index) {
                            laydate.render({
                                elem: '#time1',
                                range: true,
                                done: function (value, date, endDate) {
                                    times1 = value;

                                    if (times1.length != 0) {
                                        table.reload('table-sum1', {
                                            where: {
                                                times: times1,
                                                is_sum: 1,
                                            },
                                            url: '/warn_list/newsum_list/', // 数据接口
                                        });
                                    } else if (times1.length == 0) {
                                        parent.location.reload();
                                    }
                                    layer.close(index);
                                }
                            });
                        },
                    });
                    break;

                // 监控点筛选
                case 'dev-select':
                    layer.open({
                        resize: false,
                        type: 1,
                        title: '请勾选监控点',
                        content: $('#layer-dev-select'),
                        offset: ['150px', '690px'],
                        area: ['250px', '400px'],
                        btn: ['确认', '取消'],
                        success: function () {
                            $.ajax({
                                type: 'get',
                                url: '/public/select_dev/',
                                data: {},
                                success: function (result) {
                                    if (result['code'] === 200) {
                                        var html = template('select-dev', {
                                            'data': result['data']
                                        });
                                        document.getElementById('add-select-dev').innerHTML = html;
                                        form.render();

                                    } else {
                                        var messageObject = result['message'];
                                        if (typeof messageObject == 'string') {
                                            layer.alert(messageObject);
                                        } else {
                                            for (var key in messageObject) {
                                                var messages = messageObject[key];
                                                var message = messages[0];
                                                layer.alert(message);
                                            }
                                        }
                                    }
                                },
                                error: function () {
                                    layer.alert('获取失败，请重试...');
                                }
                            })
                        },
                        yes: function (index) {
                            obj = document.getElementsByName('dev');
                            check_val = [];
                            for (k in obj) {
                                if (obj[k].checked) {
                                    check_val.push(obj[k].value);
                                }
                            }
                            var new_dev = check_val.join(',');
                            check_dev1 = new_dev;
                            if (check_dev1.length != 0) {
                                table.reload('table-sum1', {
                                    where: {
                                        check_dev: check_dev1,
                                        is_sum: 1,
                                    },
                                    url: '/warn_list/newsum_list/', // 数据接口
                                });
                            }
                            layer.close(index);
                        }
                    });
                    break;

                // 导出数据
                case 'down-select':
                    layer.confirm('确认导出吗?', function (index) {
                        var url = '/warn_list/return_excel/?type_id=1' + '&is_sum=1' + '&check_value=' + check_value1 + '&check_dev=' + check_dev1 +
                            check_dev1 + '&check_manage=' + check_manage1 + '&check_alarm=' + check_alarm1 + '&check_day=' + check_day1 + '&times=' + times1;
                        window.location.href = url;
                        layer.close(index);
                    });
                    break;
            }
        });

        // 监听工具条 is-make=2
        table.on('tool(warnlist1)', function (obj) {
            var data = obj.data; // 获取当前行数据
            var layEvent = obj.event; // lay-event的值
            if (layEvent === 'view-image') {
                // 弹窗查看图片
                $.ajax({
                    type: 'get',
                    url: '/warn_list/warn_image/',
                    data: {
                        'id': data['id'],
                        'is_make': 2
                    },
                    success: function (result) {
                        if (result['code'] === 200) {
                            var html = template('add-image', {
                                'data': result['data']
                            });
                            document.getElementById('image-views').innerHTML = html;
                            var image_obj = $('#image0');
                            var image_views = $('#image-views');
                            var video_views = $('#video-views');
                            image_obj.click();
                            layer.photos({
                                photos: '#image-views',
                                anim: 5,
                                end: function (index) {
                                    image_views.remove();
                                    video_views.append('<div id="image-views" style="display: none"></div>');
                                }
                            });
                        } else {
                            var messageObject = result['message'];
                            if (typeof messageObject == 'string') {
                                layer.alert(messageObject);
                            } else {
                                for (var key in messageObject) {
                                    var messages = messageObject[key];
                                    var message = messages[0];
                                    layer.alert(message);
                                }
                            }
                        }
                    },
                    error: function () {
                        layer.alert('本预警暂无图片，请重试...');
                    }
                });
            }

            else if (layEvent === 'sum-warn') {
                let warn_url = data['warn_url'];
                if (warn_url.length <= 4) {
                    layer.alert('手动预警无标注图片,请选择智能预警!');
                } else {
                    // let image_sign = eval(data['image_sign']);
                    let warn_url = data['warn_url'];
                    let path = 'https://obs-swj.obs.cn-east-2.myhuaweicloud.com/';
                    let warn_image = path + warn_url;
                    json_data = {
                        'data': [
                            {'src': warn_image}
                        ]
                    };
                    layer.photos({
                        photos: json_data,
                        anim: 5
                    });
                }
            }

            else if (layEvent === 'view-video') {
                // 弹窗查看视频
                layer.open({
                    type: 1,
                    title: '播放预警视频',
                    area: ['700px', '450px'],
                    resize: false,
                    content: $('#video-views'),
                    btn: '',
                    success: function () {
                        var video_url = data['video_url']; // 获取播放地址
                        var player = videojs('play-video');
                        player.ready(function () {
                            var myPlayer = this;
                            myPlayer.reset();
                            myPlayer.src({
                                type: "video/mp4",
                                src: video_url
                            });
                            myPlayer.load(video_url); // 这个需要从新加载地址...
                            myPlayer.play(); // 点击播放
                        });
                    },
                    yes: function (index, layero) {
                        layer.close(index);
                    }
                })
            }
        });

        // ****************************************************************

        // 选项卡 - 已完成
        var check_value2 = [];
        var check_dev2 = [];
        var check_manage2 = [];
        var check_day2 = [];
        var check_alarm2 = [];
        var times2 = [];
        table.render({
            elem: '#table-sum2',
            height: 'full', // 表格高度始终填满
            // even: true, //　列表隔行颜色
            size: 'lg',
            method: 'get', // 请求方法
            url: '/warn_list/newsum_list/', // 数据接口
            where: {
                is_make: 3,
                check_value: check_value2,
                check_dev: check_dev2,
                check_manage: check_manage2,
                check_day: check_day2,
                check_alarm: check_alarm2,
                times: times2,
                is_sum: 1,
            },
            page: true, // 开启分页　可传入laypage参数
            toolbar: '#warn-tool',
            limit: 6,
            limits: [6, 20, 50, 100, 200],
            text: '暂无数据...',
            cols: [
                [ // 表头　需要显示的数据列
                    // {
                    //     type: 'checkbox',
                    //     fixed: 'left'
                    // },
                    {
                        field: 'event_id',
                        title: '预警编号',
                        sort: true,
                    },
                    {
                        field: 'type_name',
                        title: '任务类型',
                    },
                    {
                        field: 'warn_type',
                        title: '预警类型',
                    },
                    {
                        field: 'map_name',
                        title: '所属监控点',
                    },
                    {
                        field: 'result',
                        title: '执法意见',
                    },
                    {
                        field: 'manage_user',
                        title: '城管处理员'
                    },
                    {
                        field: 'user',
                        title: '平台处理员',
                    },
                    {
                        field: 'add_time',
                        title: '发生时间',
                        sort: true,
                    },
                    {
                        field: 'warn_url',
                        title: '事件图片',
                        templet: '#sum-image',
                        align: 'center',
                        width: 210,
                    },
                    {
                        field: 'images',
                        title: '证据图片',
                        templet: '#warn-image',
                        align: 'center',
                        hide: true
                    },
                    {
                        field: 'images_url',
                        title: '执法图片',
                        templet: '#manage-images',
                        align: 'center',
                    },
                    {
                        field: 'video_url',
                        title: '证据视频',
                        templet: '#warn-video',
                        align: 'center',
                    },
                ]
            ]
        });

        table.on('toolbar(warnlist2)', function (obj) {
            switch (obj.event) {
                // 任务类型筛选
                case 'manage-select':
                    layer.open({
                        resize: false,
                        type: 1,
                        title: '请勾选任务类型',
                        content: $('#layer-manage-select'),
                        offset: ['200px', '300px'],
                        area: ['300px', '200px'],
                        btn: ['确认', '取消'],
                        yes: function (index) {
                            obj = document.getElementsByName('manage');
                            check_val = [];
                            for (k in obj) {
                                if (obj[k].checked) {
                                    check_val.push(obj[k].value);
                                }
                            }
                            var new_val = check_val.join(',');
                            check_manage2 = new_val;

                            if (check_manage2.length != 0) {
                                table.reload('table-sum2', {
                                    where: {
                                        check_manage: check_manage2,
                                        is_sum: 1,
                                    },
                                    url: '/warn_list/newsum_list/', // 数据接口
                                });
                            } else if (check_manage2.length == 0) {
                                parent.location.reload();
                            }
                            layer.close(index);
                        }
                    });
                    break;

                // 预警类型筛选
                case 'warn-select':
                    layer.open({
                        resize: false,
                        type: 1,
                        title: '请勾选预警类型',
                        content: $('#layer-warn-select'),
                        offset: ['200px', '400px'],
                        area: ['300px', '200px'],
                        btn: ['确认', '取消'],
                        yes: function (index) {
                            obj = document.getElementsByName('warn');
                            check_val = [];
                            for (k in obj) {
                                if (obj[k].checked) {
                                    check_val.push(obj[k].value);
                                }
                            }
                            var new_val = check_val.join(',');
                            check_value2 = new_val;

                            if (check_value2.length != 0) {
                                table.reload('table-sum2', {
                                    where: {
                                        check_value: check_value2,
                                        is_sum: 1,
                                    },
                                    url: '/warn_list/newsum_list/', // 数据接口
                                });
                            } else if (check_value2.length == 0) {
                                parent.location.reload();
                            }
                            layer.close(index);
                        }
                    });
                    break;

                // 事件类型
                case 'alarm-select':
                    layer.open({
                        resize: false,
                        type: 1,
                        title: '请勾选条件',
                        content: $('#layer-alarm-select'),
                        offset: ['200px', '500px'],
                        area: ['300px', '200px'],
                        btn: ['确认', '取消'],
                        yes: function (index) {
                            obj = document.getElementsByName('alarm');
                            check_alarm = [];
                            for (k in obj) {
                                if (obj[k].checked) {
                                    check_alarm.push(obj[k].value);
                                }
                            }
                            var new_alarm = check_alarm.join(',');
                            check_alarm2 = new_alarm;

                            if (check_alarm2.length != 0) {
                                table.reload('table-sum2', {
                                    where: {
                                        check_alarm: check_alarm2,
                                        is_sum: 1,
                                    },
                                    url: '/warn_list/newsum_list/', // 数据接口
                                });
                            } else if (check_alarm2.length == 0) {
                                parent.location.reload();
                            }
                            layer.close(index);
                        }
                    });
                    break;

                // 昼夜筛选
                case 'day-select':
                    layer.open({
                        resize: false,
                        type: 1,
                        title: '请勾选条件',
                        content: $('#layer-day-select'),
                        offset: ['200px', '600px'],
                        area: ['300px', '200px'],
                        btn: ['确认', '取消'],
                        yes: function (index) {
                            obj = document.getElementsByName('day');
                            check_day = [];
                            for (k in obj) {
                                if (obj[k].checked) {
                                    check_day.push(obj[k].value);
                                }
                            }
                            var new_val = check_day.join(',');
                            check_day2 = new_val;

                            if (check_day2.length != 0) {
                                table.reload('table-sum2', {
                                    where: {
                                        check_day: check_day2,
                                        is_sum: 1,
                                    },
                                    url: '/warn_list/newsum_list/', // 数据接口
                                });
                            } else if (check_day2.length == 0) {
                                parent.location.reload();
                            }
                            layer.close(index);
                        }
                    });
                    break;

                // 时间筛选
                case 'time-select':
                    layer.open({
                        resize: false,
                        type: 1,
                        title: '筛选时间',
                        content: $('#layer-time-select2'),
                        offset: ['200px', '600px'],
                        area: ['600px', '480px'],
                        success: function (layero, index) {
                            laydate.render({
                                elem: '#time2',
                                range: true,
                                done: function (value, date, endDate) {
                                    times2 = value;

                                    if (times2.length != 0) {
                                        table.reload('table-sum2', {
                                            where: {
                                                times: times2,
                                                is_sum: 1,
                                            },
                                            url: '/warn_list/newsum_list/', // 数据接口
                                        });
                                    } else if (times2.length == 0) {
                                        parent.location.reload();
                                    }
                                    layer.close(index);
                                }
                            });
                        },
                    });
                    break;

                // 监控点筛选
                case 'dev-select':
                    layer.open({
                        resize: false,
                        type: 1,
                        title: '请勾选监控点',
                        content: $('#layer-dev-select'),
                        offset: ['150px', '690px'],
                        area: ['250px', '400px'],
                        btn: ['确认', '取消'],
                        success: function () {
                            $.ajax({
                                type: 'get',
                                url: '/public/select_dev/',
                                data: {},
                                success: function (result) {
                                    if (result['code'] === 200) {
                                        var html = template('select-dev', {
                                            'data': result['data']
                                        });
                                        document.getElementById('add-select-dev').innerHTML = html;
                                        form.render();

                                    } else {
                                        var messageObject = result['message'];
                                        if (typeof messageObject == 'string') {
                                            layer.alert(messageObject);
                                        } else {
                                            for (var key in messageObject) {
                                                var messages = messageObject[key];
                                                var message = messages[0];
                                                layer.alert(message);
                                            }
                                        }
                                    }
                                },
                                error: function () {
                                    layer.alert('获取失败，请重试...');
                                }
                            })
                        },
                        yes: function (index) {
                            obj = document.getElementsByName('dev');
                            check_val = [];
                            for (k in obj) {
                                if (obj[k].checked) {
                                    check_val.push(obj[k].value);
                                }
                            }
                            var new_dev = check_val.join(',');
                            check_dev2 = new_dev;
                            if (check_dev2.length != 0) {
                                table.reload('table-sum2', {
                                    where: {
                                        check_dev: check_dev2,
                                        is_sum: 1,
                                    },
                                    url: '/warn_list/newsum_list/', // 数据接口
                                });
                            }
                            layer.close(index);
                        }
                    });
                    break;

                // 导出数据
                case 'down-select':
                    layer.confirm('确认导出吗?', function (index) {
                        var url = '/warn_list/return_excel/?type_id=2' + '&is_sum=1' + '&check_value=' + check_value2 + '&check_dev=' + check_dev2 +
                            check_dev2 + '&check_manage=' + check_manage2 + '&check_alarm=' + check_alarm2 + '&check_day=' + check_day2 + '&times=' + times2;
                        window.location.href = url;
                        layer.close(index);
                    });
                    break;
            }
        });

        //　监听工具条 is-make=3
        table.on('tool(warnlist2)', function (obj) {
            var data = obj.data; // 获取当前行数据
            var layEvent = obj.event; // lay-event的值
            if (layEvent === 'view-image') {
                // 弹窗查看图片
                $.ajax({
                    type: 'get',
                    url: '/warn_list/warn_image/',
                    data: {
                        'id': data['id'],
                    },
                    success: function (result) {
                        if (result['code'] === 200) {
                            var html = template('add-image', {
                                'data': result['data']
                            });
                            document.getElementById('image-views').innerHTML = html;
                            var image_obj = $('#image0');
                            var image_views = $('#image-views');
                            var video_views = $('#video-views');
                            image_obj.click();
                            layer.photos({
                                photos: '#image-views',
                                anim: 5,
                                end: function (index) {
                                    image_views.remove();
                                    video_views.append('<div id="image-views" style="display: none"></div>');
                                }
                            });
                        } else {
                            var messageObject = result['message'];
                            if (typeof messageObject == 'string') {
                                layer.alert(messageObject);
                            } else {
                                for (var key in messageObject) {
                                    var messages = messageObject[key];
                                    var message = messages[0];
                                    layer.alert(message);
                                }
                            }
                        }
                    },
                    error: function () {
                        layer.alert('本预警暂无图片，请重试...');
                    }
                });
            }

            else if (layEvent === 'sum-warn') {
                let warn_url = data['warn_url'];
                if (warn_url.length <= 4) {
                    layer.alert('手动预警无标注图片,请选择智能预警!');
                } else {
                    // let image_sign = eval(data['image_sign']);
                    let warn_url = data['warn_url'];
                    let path = 'https://obs-swj.obs.cn-east-2.myhuaweicloud.com/';
                    let warn_image = path + warn_url;
                    json_data = {
                        'data': [
                            {'src': warn_image}
                        ]
                    };
                    layer.photos({
                        photos: json_data,
                        anim: 5
                    });
                }
            }

            else if (layEvent === 'view-video') {
                // 弹窗查看视频
                layer.open({
                    type: 1,
                    title: '播放预警视频',
                    area: ['700px', '450px'],
                    resize: false,
                    content: $('#video-views'),
                    btn: '',
                    success: function () {
                        var video_url = data['video_url']; // 获取播放地址
                        var player = videojs('play-video');
                        player.ready(function () {
                            var myPlayer = this;
                            myPlayer.reset();
                            myPlayer.src({
                                type: "video/mp4",
                                src: video_url
                            });
                            myPlayer.load(video_url); // 这个需要从新加载地址...
                            myPlayer.play(); // 点击播放
                        });
                    },
                    yes: function (index, layero) {
                        layer.close(index);
                    }
                })
            }
            else if (layEvent === 'manage-image') {
                // 弹窗查看执法图片
                $.ajax({
                    type: 'get',
                    url: '/warn_list/manage_image/',
                    data: {
                        'id': data['id'],
                    },
                    success: function (result) {
                        if (result['code'] === 200) {
                            console.log(result['data']);
                            var html = template('add-manage', {
                                'data': result['data']
                            });

                            document.getElementById('manage-views').innerHTML = html;
                            var images_obj = $('#images0');
                            var images_views = $('#manage-views');
                            var video_views = $('#image-views');
                            images_obj.click();
                            layer.photos({
                                photos: '#manage-views',
                                anim: 5,
                                end: function (index) {
                                    images_views.remove();
                                    video_views.append('<div id="manage-views" style="display: none"></div>');
                                }
                            });
                        } else {
                            var messageObject = result['message'];
                            if (typeof messageObject == 'string') {
                                layer.alert(messageObject);
                            } else {
                                for (var key in messageObject) {
                                    var messages = messageObject[key];
                                    var message = messages[0];
                                    layer.alert(message);
                                }
                            }
                        }
                    },
                    error: function () {
                        layer.alert('本预警暂无图片，请重试...');
                    }
                });

            }
        });

        // ****************************************************************

        // 选项卡 - 已丢弃
        var check_value3 = [];
        var check_dev3 = [];
        var check_manage3 = [];
        var check_day3 = [];
        var check_alarm3 = [];
        var times3 = [];
        table.render({
            elem: '#table-sum3',
            height: 'full', // 表格高度始终填满
            // even: true, //　列表隔行颜色
            size: 'lg',
            method: 'get', // 请求方法
            url: '/warn_list/newsum_list/', // 数据接口
            where: {
                'is_make': 4,
                check_value: check_value3,
                check_dev: check_dev3,
                check_manage: check_manage3,
                check_day: check_day3,
                check_alarm: check_alarm3,
                times: times3,
                is_sum: 1,
            },
            page: true, // 开启分页　可传入laypage参数
            toolbar: '#warn-tool',
            limit: 6,
            limits: [6, 20, 50, 100, 200],
            text: '暂无数据...',
            cols: [
                [ // 表头　需要显示的数据列
                    // {
                    //     type: 'checkbox',
                    //     fixed: 'left'
                    // },
                    {
                        field: 'event_id',
                        title: '预警编号',
                        sort: true,
                    },
                    {
                        field: 'type_name',
                        title: '任务类型',
                    },
                    {
                        field: 'warn_type',
                        title: '预警类型',
                    },
                    {
                        field: 'map_name',
                        title: '所属监控点',
                    },
                    {
                        field: 'result',
                        title: '当前状态',
                    },
                    {
                        field: 'manage_user',
                        title: '城管处理员',
                        // hide: true
                    },
                    {
                        field: 'user',
                        title: '平台处理员',
                    },
                    {
                        field: 'add_time',
                        title: '发生时间',
                        sort: true,
                    },
                    {
                        field: 'warn_url',
                        title: '事件图片',
                        templet: '#sum-image',
                        align: 'center',
                        width: 210,
                    },
                    {
                        field: 'images',
                        title: '证据图片',
                        templet: '#warn-image',
                        align: 'center',
                        hide: true
                    },
                    {
                        field: 'video_url',
                        title: '证据视频',
                        templet: '#warn-video',
                        align: 'center',
                    },
                ]
            ]
        });

        table.on('toolbar(warnlist3)', function (obj) {
            switch (obj.event) {
                // 任务类型筛选
                case 'manage-select':
                    layer.open({
                        resize: false,
                        type: 1,
                        title: '请勾选任务类型',
                        content: $('#layer-manage-select'),
                        offset: ['200px', '300px'],
                        area: ['300px', '200px'],
                        btn: ['确认', '取消'],
                        yes: function (index) {
                            obj = document.getElementsByName('manage');
                            check_val = [];
                            for (k in obj) {
                                if (obj[k].checked) {
                                    check_val.push(obj[k].value);
                                }
                            }
                            var new_val = check_val.join(',');
                            check_manage3 = new_val;

                            if (check_manage3.length != 0) {
                                table.reload('table-sum3', {
                                    where: {
                                        check_manage: check_manage3,
                                        is_sum: 1,
                                    },
                                    url: '/warn_list/newsum_list/', // 数据接口
                                });
                            } else if (check_manage3.length == 0) {
                                parent.location.reload();
                            }
                            layer.close(index);
                        }
                    });
                    break;

                // 预警类型筛选
                case 'warn-select':
                    layer.open({
                        resize: false,
                        type: 1,
                        title: '请勾选预警类型',
                        content: $('#layer-warn-select'),
                        offset: ['200px', '400px'],
                        area: ['300px', '200px'],
                        btn: ['确认', '取消'],
                        yes: function (index) {
                            obj = document.getElementsByName('warn');
                            check_val = [];
                            for (k in obj) {
                                if (obj[k].checked) {
                                    check_val.push(obj[k].value);
                                }
                            }
                            var new_val = check_val.join(',');
                            check_value3 = new_val;

                            if (check_value3.length != 0) {
                                table.reload('table-sum3', {
                                    where: {
                                        check_value: check_value3,
                                        is_sum: 1,
                                    },
                                    url: '/warn_list/newsum_list/', // 数据接口
                                });
                            } else if (check_value3.length == 0) {
                                parent.location.reload();
                            }
                            layer.close(index);
                        }
                    });
                    break;

                // 事件类型
                case 'alarm-select':
                    layer.open({
                        resize: false,
                        type: 1,
                        title: '请勾选条件',
                        content: $('#layer-alarm-select'),
                        offset: ['200px', '500px'],
                        area: ['300px', '200px'],
                        btn: ['确认', '取消'],
                        yes: function (index) {
                            obj = document.getElementsByName('alarm');
                            check_alarm = [];
                            for (k in obj) {
                                if (obj[k].checked) {
                                    check_alarm.push(obj[k].value);
                                }
                            }
                            var new_alarm = check_alarm.join(',');
                            check_alarm3 = new_alarm;

                            if (check_alarm3.length != 0) {
                                table.reload('table-sum3', {
                                    where: {
                                        check_alarm: check_alarm3,
                                        is_sum: 1,
                                    },
                                    url: '/warn_list/newsum_list/', // 数据接口
                                });
                            } else if (check_alarm3.length == 0) {
                                parent.location.reload();
                            }
                            layer.close(index);
                        }
                    });
                    break;

                // 昼夜筛选
                case 'day-select':
                    layer.open({
                        resize: false,
                        type: 1,
                        title: '请勾选条件',
                        content: $('#layer-day-select'),
                        offset: ['200px', '600px'],
                        area: ['300px', '200px'],
                        btn: ['确认', '取消'],
                        yes: function (index) {
                            obj = document.getElementsByName('day');
                            check_day = [];
                            for (k in obj) {
                                if (obj[k].checked) {
                                    check_day.push(obj[k].value);
                                }
                            }
                            var new_val = check_day.join(',');
                            check_day3 = new_val;

                            if (check_day3.length != 0) {
                                table.reload('table-sum3', {
                                    where: {
                                        check_day: check_day3,
                                        is_sum: 1,
                                    },
                                    url: '/warn_list/newsum_list/', // 数据接口
                                });
                            } else if (check_day3.length == 0) {
                                parent.location.reload();
                            }
                            layer.close(index);
                        }
                    });
                    break;

                // 时间筛选
                case 'time-select':
                    layer.open({
                        resize: false,
                        type: 1,
                        title: '筛选时间',
                        content: $('#layer-time-select3'),
                        offset: ['200px', '600px'],
                        area: ['600px', '480px'],
                        success: function (layero, index) {
                            laydate.render({
                                elem: '#time3',
                                range: true,
                                done: function (value, date, endDate) {
                                    times3 = value;

                                    if (times3.length != 0) {
                                        table.reload('table-sum3', {
                                            where: {
                                                times: times3,
                                                is_sum: 1,
                                            },
                                            url: '/warn_list/newsum_list/', // 数据接口
                                        });
                                    } else if (times3.length == 0) {
                                        parent.location.reload();
                                    }
                                    layer.close(index);
                                }
                            });
                        },
                    });
                    break;

                // 监控点筛选
                case 'dev-select':
                    layer.open({
                        resize: false,
                        type: 1,
                        title: '请勾选监控点',
                        content: $('#layer-dev-select'),
                        offset: ['150px', '690px'],
                        area: ['250px', '400px'],
                        btn: ['确认', '取消'],
                        success: function () {
                            $.ajax({
                                type: 'get',
                                url: '/public/select_dev/',
                                data: {},
                                success: function (result) {
                                    if (result['code'] === 200) {
                                        var html = template('select-dev', {
                                            'data': result['data']
                                        });
                                        document.getElementById('add-select-dev').innerHTML = html;
                                        form.render();

                                    } else {
                                        var messageObject = result['message'];
                                        if (typeof messageObject == 'string') {
                                            layer.alert(messageObject);
                                        } else {
                                            for (var key in messageObject) {
                                                var messages = messageObject[key];
                                                var message = messages[0];
                                                layer.alert(message);
                                            }
                                        }
                                    }
                                },
                                error: function () {
                                    layer.alert('获取失败，请重试...');
                                }
                            })
                        },
                        yes: function (index) {
                            obj = document.getElementsByName('dev');
                            check_val = [];
                            for (k in obj) {
                                if (obj[k].checked) {
                                    check_val.push(obj[k].value);
                                }
                            }
                            var new_dev = check_val.join(',');
                            check_dev3 = new_dev;
                            if (check_dev3.length != 0) {
                                table.reload('table-sum3', {
                                    where: {
                                        check_dev: check_dev3,
                                        is_sum: 1,
                                    },
                                    url: '/warn_list/newsum_list/', // 数据接口
                                });
                            }
                            layer.close(index);
                        }
                    });
                    break;

                // 导出数据
                case 'down-select':
                    layer.confirm('确认导出吗?', function (index) {
                        var url = '/warn_list/return_excel/?type_id=3' + '&is_sum=1' + '&check_value=' + check_value3 + '&check_dev=' + check_dev3 +
                            check_dev3 + '&check_manage=' + check_manage3 + '&check_alarm=' + check_alarm3 + '&check_day=' + check_day3 + '&times=' + times3;
                        window.location.href = url;
                        layer.close(index);
                    });
                    break;
            }
        });

        //　监听工具条 is-make=4
        table.on('tool(warnlist3)', function (obj) {
            var data = obj.data; // 获取当前行数据
            var layEvent = obj.event; // lay-event的值
            if (layEvent === 'view-image') {
                // 弹窗查看图片
                $.ajax({
                    type: 'get',
                    url: '/warn_list/warn_image/',
                    data: {
                        'id': data['id'],
                        'is_make': 4
                    },
                    success: function (result) {
                        if (result['code'] === 200) {
                            var html = template('add-image', {
                                'data': result['data']
                            });
                            document.getElementById('image-views').innerHTML = html;
                            var image_obj = $('#image0');
                            var image_views = $('#image-views');
                            var video_views = $('#video-views');
                            image_obj.click();
                            layer.photos({
                                photos: '#image-views',
                                anim: 5,
                                end: function (index) {
                                    image_views.remove();
                                    video_views.append('<div id="image-views" style="display: none"></div>');
                                }
                            });
                        } else {
                            var messageObject = result['message'];
                            if (typeof messageObject == 'string') {
                                layer.alert(messageObject);
                            } else {
                                for (var key in messageObject) {
                                    var messages = messageObject[key];
                                    var message = messages[0];
                                    layer.alert(message);
                                }
                            }
                        }
                    },
                    error: function () {
                        layer.alert('本预警暂无图片，请重试...');
                    }
                });
            }

            else if (layEvent === 'sum-warn') {
                let warn_url = data['warn_url'];
                if (warn_url.length <= 4) {
                    layer.alert('手动预警无标注图片,请选择智能预警!');
                } else {
                    // let image_sign = eval(data['image_sign']);
                    let warn_url = data['warn_url'];
                    let path = 'https://obs-swj.obs.cn-east-2.myhuaweicloud.com/';
                    let warn_image = path + warn_url;
                    json_data = {
                        'data': [
                            {'src': warn_image}
                        ]
                    };
                    layer.photos({
                        photos: json_data,
                        anim: 5
                    });
                }
            }

            else if (layEvent === 'view-video') {
                // 弹窗查看视频
                layer.open({
                    type: 1,
                    title: '播放预警视频',
                    area: '700px',
                    resize: false,
                    content: $('#video-views'),
                    btn: '点击关闭',
                    success: function () {
                        var video_url = data['video_url']; // 获取播放地址
                        var player = videojs('play-video');
                        player.ready(function () {
                            var myPlayer = this;
                            myPlayer.reset();
                            myPlayer.src({
                                type: "video/mp4",
                                src: video_url
                            });
                            myPlayer.load(video_url); // 这个需要从新加载地址...
                            myPlayer.play(); // 点击播放
                        });
                    },
                    yes: function (index, layero) {
                        layer.close(index);
                    }
                })
            }
        });
    });
};


$(function () {
    var sum_list = new SumList();
    sum_list.run();
});